package ar.com.fiuba.team2.chat;

public class MessagerProxy implements ar.com.fiuba.team2.chat.Messager {
  private String _endpoint = null;
  private ar.com.fiuba.team2.chat.Messager messager = null;
  
  public MessagerProxy() {
    _initMessagerProxy();
  }
  
  public MessagerProxy(String endpoint) {
    _endpoint = endpoint;
    _initMessagerProxy();
  }
  
  private void _initMessagerProxy() {
    try {
      messager = (new ar.com.fiuba.team2.chat.MessagerServiceLocator()).getMessager();
      if (messager != null) {
        if (_endpoint != null)
          ((javax.xml.rpc.Stub)messager)._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);
        else
          _endpoint = (String)((javax.xml.rpc.Stub)messager)._getProperty("javax.xml.rpc.service.endpoint.address");
      }
      
    }
    catch (javax.xml.rpc.ServiceException serviceException) {}
  }
  
  public String getEndpoint() {
    return _endpoint;
  }
  
  public void setEndpoint(String endpoint) {
    _endpoint = endpoint;
    if (messager != null)
      ((javax.xml.rpc.Stub)messager)._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);
    
  }
  
  public ar.com.fiuba.team2.chat.Messager getMessager() {
    if (messager == null)
      _initMessagerProxy();
    return messager;
  }
  
  public ar.com.fiuba.team2.model.Chat sendMessage(long chatId, long memberId, java.lang.String message) throws java.rmi.RemoteException{
    if (messager == null)
      _initMessagerProxy();
    return messager.sendMessage(chatId, memberId, message);
  }
  
  public ar.com.fiuba.team2.model.Chat updateChat(long chatId) throws java.rmi.RemoteException{
    if (messager == null)
      _initMessagerProxy();
    return messager.updateChat(chatId);
  }
  
  public ar.com.fiuba.team2.model.Chat createChat(long scopeId) throws java.rmi.RemoteException{
    if (messager == null)
      _initMessagerProxy();
    return messager.createChat(scopeId);
  }
  
  public ar.com.fiuba.team2.model.Chat getHistoryChat(long chatId) throws java.rmi.RemoteException{
    if (messager == null)
      _initMessagerProxy();
    return messager.getHistoryChat(chatId);
  }
  
  
}